from fastapi import APIRouter, Depends

from sqlalchemy import desc, select, func
from sqlalchemy.orm import Session

from apis.deps import get_db
from models import TestReport

router = APIRouter()


@router.get("/getReportList")
async def getReportList(pageIndex: int, pageSize: int, queryName: str = '', projectId: int = 0,
                        db: Session = Depends(get_db)):
    """
    获取测试报告列表
    """
    getReportList_sql = await db.execute(
        select(TestReport).offset((pageIndex - 1) * pageSize).limit(pageSize).order_by(desc(TestReport.id)))
    getReportList = getReportList_sql.scalars().all()
    count_testReport_sql = await db.execute(func.count(TestReport.id))
    count_testReport = count_testReport_sql.scalars().first()
    db.close()
    return {"code": 200, "msg": "success", "data": {"list": getReportList, "count": count_testReport}}
